const express = require('express');
const router = express.Router();

// 模拟数据，实际应从数据库获取
const billiardRooms = [
    {
        room_id: 1,
        room_name: '中山电子科技大学店',
        location: '广东省中山市石岐区街道龙凤街4号溢彩荟2期4楼403小铁24h无人自助台...',
        number_of_tables: 5,
        available_tables: 3,
        hourly_rate: 28.0,
        createdtime: new Date()
    },
    {
        room_id: 2,
        room_name: '中山石岐新都会店',
        location: '广东省中山市大信中路石岐大信新都汇A座2层',
        number_of_tables: 6,
        available_tables: 6,
        hourly_rate: 28.0,
        createdtime: new Date()
    }
];

// 获取所有台球室 / 按位置搜索
router.get('/api/billiard_rooms', (req, res) => {
    const { location } = req.query;
    let filtered = [...billiardRooms];

    if (location) {
        filtered = filtered.filter(room =>
            room.location.toLowerCase().includes(location.toLowerCase())
        );
    }

    res.json({
        code: 0,
        data: filtered
    });
});

module.exports = router;
